﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class TLS06
    {

        public TLS06()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VLIEFKO();
            DataContext = MV;
            InitializeComponent();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                KEY = "";
                LIEFBED = "";
                ZAHLBED = "";
                VSPED = "";
                SART = "";
            }
            else
            {
                KEY = (dwMaster["LSKLIEFNR"].ToString() + dwMaster["LSKKONDSL"].ToString()).PadRight(12);
                TXTISIND = KEY.PadRight(60);
                LIEFBED = dwMaster["LSKLIEFBED"].ToString();
                ZAHLBED = dwMaster["LSKZAHLBED"].ToString();
                VSPED = dwMaster["LSKSPEDSL"].ToString();
                SART = dwMaster["LSKVERSART"].ToString();
            }
        }
        public override void LOADBYAUF()
        { 
            base.LOADBYAUF();
            TBMain.Clear();
            if (ORDERNUM.Length < 12)
                return;
            dwData = TBMain.NewRow();
            dwData["LSKMANDANT"] = app.Mandant;
            dwData["LSKLIEFNR"] = ORDERNUM.Substring(0,8);
            dwData["LSKKONDSL"] = ORDERNUM.Substring(8, 4);
            SResult = ((VLIEFKO)MV).QueryLIEFKO(dwData, 2);
            MergeData(SResult, true); 
        }
        public override void OnSave()
        {
            if (dwMaster == null)
                return;
            if (!IsSaved)
                return;
            ((VLIEFKO)MV).UpdateLIEFKO(dwMaster, app.company, 0);
            string key = KEY;
            KEY = "";
            KEY = key;
            
            base.OnSave();
        }
    }
}
